package com.egg.mall.controller.api;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.egg.auth.feign.AuthUserFeignClient;
import com.egg.auth.model.request.web.UserPagePostFeign;
import com.egg.auth.model.response.web.UserPage;
import com.egg.common.core.model.controller.ApiController;
import com.egg.common.core.model.controller.WebController;
import com.egg.common.core.model.request.StateRequest;
import com.egg.common.core.model.response.PageData;
import com.egg.common.core.model.response.ResponseData;
import com.egg.common.util.JsonUtil;
import com.egg.mall.entity.sku.orders.SkuOrders;
import com.egg.mall.enums.OrderStateEnum;
import com.egg.mall.model.request.OrderPostOrPut;
import com.egg.mall.model.response.web.OrderPage;
import com.egg.mall.service.sku.order.ISkuOrdersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * <p>
 * 订单 前端控制器
 * </p>
 *
 * @author east
 * @since 2022-08-27
 */
@Slf4j
@Api(tags = ApiController.API_PREFIX + "订单")
@RestController
@RequestMapping("/sku/orders")
public class ApiSkuOrdersController extends ApiController {


    @Autowired
    private ISkuOrdersService skuOrdersService;


    @ApiOperation(value = "订单新增并拉起支付")
    @PostMapping
    public ResponseData<String> skuOrdersAddAndPayPost(@RequestBody OrderPostOrPut param) {
        String pay = skuOrdersService.addAndPay(param);
        return ResponseData.success(pay);
    }

    @ApiOperation(value = "订单拉起支付")
    @GetMapping("/{id}/pay")
    public ResponseData<String> skuOrdersPayGet(
            @ApiParam(value = "订单ID", required = true) @PathVariable String id
            , @ApiParam(value = "支付类型", required = true) @RequestParam(value = "payType") String payType
            , @ApiParam(value = "客户端类型", required = true) @RequestParam(value = "clientType") String clientType
    ) {
        String pay = skuOrdersService.pay(id, payType, clientType);
        return ResponseData.success(pay);
    }


}

